<template>
  <div class="container">
    <!-- <div class="header-img"></div> -->
    <div class="title">
      <h1>智慧校园大数据分析平台</h1>
      <h5>Intelligent Campus Big Data Analysis Platform</h5>
    </div>
    <div class="nav">
      <a :href="item.link" v-for="(item,idx) in navList" :key="idx">
        <div class="item" :style="{background:item.bgColor}">
          <div class="img">
            <img :src="item.imgSrc" alt>
          </div>
          <div class="info">
            <p class="en">{{item.en}}</p>
            <p class="cn">{{item.cn}}</p>
          </div>
        </div>
      </a>
    </div>
    <div class="content">
      <div class="pie-chart">
        <div class="header">
          <span class="title">各级师资占比</span>
          <span class="url-link">
            <el-dropdown trigger="click" :hide-on-click="true" @command="selectCollege">
              <span class="el-dropdown-link">
                全部学院
                <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="(item,idx) in AllCollege" :key="idx" :command="item.id">
                  <span>{{item.name}}</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </span>
        </div>
        <div class="chart">
          <pieChart ref="pieChart"/>
        </div>
      </div>
      <div class="bar-chart">
        <barChart/>
      </div>
    </div>
    <div class="content top-wrap">
      <div class="box">
        <span class="title">各学院项目数排名</span>
        <div class="table-wrap">
          <Vtable :tableData="project" columnName="项目数" height="280px"/>
        </div>
      </div>
      <div class="box">
        <span class="title">各学院论文数排名</span>
        <div class="table-wrap">
          <Vtable :tableData="parernum" columnName="论文数" height="280px"/>
        </div>
      </div>
      <div class="box">
        <span class="title">部门教职工前5名</span>
        <div class="table-wrap">
          <Vtable :tableData="top5" columnName="人数" height="280px"/>
        </div>
      </div>
    </div>
    <div class="footer">
      <footer>© 广西民族大学 & 成都寻道科技</footer>
    </div>
  </div>
</template>

<script>
import Vtable from "./components/table";
import pieChart from "./components/pieChart";
import barChart from "./components/barChart";
import { mapActions, mapState } from "vuex";
import { _getUserInfo, _getApplications, _logout } from "@/api/user.js";
export default {
  data() {
    return {
      tableData: [
        { num: "1", name: "信息与通信工程学院", nums: "50", progress: 50 },
        { num: "2", name: "信息与通信工程学院", nums: "50", progress: 60 },
        { num: "3", name: "信息与通信工程学院", nums: "50", progress: 100 },
        { num: "4", name: "信息与通信工程学院", nums: "50", progress: 90 },
        { num: "5", name: "信息与通信工程学院", nums: "50", progress: 80 }
      ],
      navList: [
        {
          imgSrc: require("../../assets/images/1.png"),
          bgColor: "#eff7ff",
          link: "#",
          en: "School situation",
          cn: "校情驾驶舱"
        },
        {
          imgSrc: require("../../assets/images/2.png"),
          bgColor: "#f5fff7",
          link: "#",
          en: "Student portrait",
          cn: "学生画像"
        },
        {
          imgSrc: require("../../assets/images/3.png"),
          bgColor: "#eff7ff",
          link: "#",
          en: "Teacher portrait",
          cn: "教师画像"
        },
        {
          imgSrc: require("../../assets/images/4.png"),
          bgColor: "#f5fff7",
          link: "#",
          en: "Data service",
          cn: "数据服务"
        },
        {
          imgSrc: require("../../assets/images/5.png"),
          bgColor: "#eff7ff",
          link: "#",
          en: "Data intelligence",
          cn: "数据智能"
        },
        {
          imgSrc: require("../../assets/images/6.png"),
          bgColor: "#f5fff7",
          link: "#",
          en: "Data governance",
          cn: "数据治理"
        },
        {
          imgSrc: require("../../assets/images/7.png"),
          bgColor: "#eff7ff",
          link: "#",
          en: "Data storage",
          cn: "数据存储"
        }
      ]
    };
  },
  computed: {
    ...mapState({
      allCollege: state => state.home.allCollege,
      teacherRatio: state => state.home.teacherRatio,
      project_parernum: state => state.home.project_parernum,
      teacherTop: state => state.home.teacherTop
    }),
    top5() {
      let arr = [];
      let count = 0;
      this.teacherTop &&
        this.teacherTop.forEach(v => {
          count += v.count;
        });
      this.teacherTop &&
        this.teacherTop.forEach(v => {
          v.progress = Number(((v.count / count) * 100).toFixed(0));
          arr.push(v);
        });
      return arr;
    },
    project() {
      let arr = [];
      let count = 0;
      this.project_parernum.projectRank &&
        this.project_parernum.projectRank.forEach(v => {
          count += v.count;
        });
      this.project_parernum.projectRank &&
        this.project_parernum.projectRank.forEach(v => {
          v.progress = Number(((v.count / count) * 100).toFixed(0));
          arr.push(v);
        });
      return arr;
    },
    parernum() {
      let arr = [];
      let count = 0;
      this.project_parernum.paperRank &&
        this.project_parernum.paperRank.forEach(v => {
          count += v.count;
        });
      this.project_parernum.paperRank &&
        this.project_parernum.paperRank.forEach(v => {
          v.progress = Number(((v.count / count) * 100).toFixed(0));
          arr.push(v);
        });
      return arr;
    },
    AllCollege() {
      let item = {
        id: null,
        name: "全部"
      };
      let data = this.allCollege;
      data.unshift(item);
      return data;
    }
  },
  methods: {
    ...mapActions({
      getAllCollege: "home/getAllCollege",
      getTeacherRatio: "home/getTeacherRatio",
      findCollegeProjectAndPaperNum: "home/findCollegeProjectAndPaperNum",
      findDepartmentTeacherTop5: "home/findDepartmentTeacherTop5",
      getUserInfo:"user/getUserInfo"
    }),
    getLink() {
      _getApplications().then(res => {
        for (let k in res) {
            this.navList.forEach(v => {
              res[k].forEach(item => {
                if (item.name == v.cn) {
                  v.link = item.url;
                }
              });
            });
        }
      });
    },
    async selectCollege(id) {
      await this.getTeacherRatio({ collegeId: id });
      this.$refs.pieChart.pieConfigure();
    }
  },
  mounted() {
    this.getAllCollege();
    this.findCollegeProjectAndPaperNum();
    this.findDepartmentTeacherTop5();
    this.getUserInfo()
    this.getLink()
  },
  components: {
    Vtable,
    pieChart,
    barChart
  }
};
</script>
<style lang="scss">
.el-dropdown-menu {
  height: 280px;
  overflow: auto;
}
.el-dropdown {
  color: #4285e6;
}
</style>

<style lang="scss" scoped>
.container {
  background: none;
  padding: 0;
  .title {
    color: #fff;
    text-align: center;
    h1 {
      font-size: 40px;
      margin: 5px 0 10px 0;
    }
    h5 {
      font-size: 14px;
      font-weight: 500;
    }
  }
  .nav {
    display: flex;
    justify-content: space-around;
    margin-top: 50px;
    a:hover .item {
      transform: scale(1.1);
    }
    .item {
      transition: all 0.5s ease;
      display: flex;
      align-items: center;
      width: 200px;
      //flex: 1;
      height: 80px;
      background: #fff;
      border-radius: 6px;
      position: relative;
      padding: 15px 10px 15px 15px;
      user-select: none;

      .img {
        padding-right: 10px;
        font-size: 12px;
      }
      .info {
        font-family: "Microsoft YaHei";
        p {
          padding: 4px 5px;
        }
        .en {
          font-size: 12px;
          color: rgb(153, 153, 153);
        }
        .cn {
          font-size: 22px;
          font-weight: 500;
          color: rgb(51, 51, 51);
        }
      }
    }
  }
  .content {
    font-size: 12px;
    margin-top: 40px;
    display: flex;
    justify-content: space-between;
    .title {
      font-size: 20px;
      font-weight: 600;
      color: #333333 !important;
    }
    .pie-chart {
      box-shadow: 0px 1px 15px 1px rgba(0, 0, 0, 0.1);
      padding: 15px;
      width: 340px;
      height: 400px;
      background: #fff;
      border-radius: 10px;
      .url-link {
        float: right;
        padding: 4px;
        font-size: 14px;
        color: #4285e6;
        cursor: pointer;
        user-select: none;
      }
    }
    .bar-chart {
      box-shadow: 0px 1px 15px 1px rgba(0, 0, 0, 0.1);
      flex: 1;
      background: #fff;
      height: 400px;
      border-radius: 10px;
      margin-left: 20px;
    }
  }
  .top-wrap {
    .box {
      flex: 1;
      height: 350px;
      background: #fff;
      margin: 0 10px;
      border-radius: 10px;
      box-shadow: 0px 1px 15px 1px rgba(0, 0, 0, 0.1);
      padding: 20px;
      min-width: 460px;
      &:first-of-type {
        margin: 0;
      }
      &:last-of-type {
        margin: 0;
      }
      .table-wrap {
        margin-top: 15px;
      }
    }
  }
  .footer {
  font-size: 18px;
  font-family: "Microsoft YaHei";
  color: rgb( 98, 98, 98 );
  text-align: center;
  margin: 20px;
  }
}
</style>

